# Contributor: Dennis Krupenik <dennis@krupenik.com>
# Maintainer: Dennis Krupenik <dennis@krupenik.com>
pkgname=spirv-llvm-translator
_pkgname=SPIRV-LLVM-Translator
pkgver=12.0.0
pkgrel=2
pkgdesc="Library for bi-directional translation between SPIR-V and LLVM IR"
url="https://github.com/KhronosGroup/SPIRV-LLVM-Translator"
arch="all"
license="NCSA"
_llvmver=12
depends_dev="clang-dev llvm$_llvmver-dev spirv-tools-dev"
makedepends="$depends_dev cmake llvm$_llvmver-static libxml2-dev samurai"
checkdepends="llvm$_llvmver-test-utils"
subpackages="$pkgname-dev"
source="https://github.com/KhronosGroup/SPIRV-LLVM-Translator/archive/v$pkgver/$_pkgname-$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

case "$CARCH" in
	x86_64) ;;
	# Failing tests
	*) options="!check";;
esac

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DLLVM_SPIRV_INCLUDE_TESTS=1 \
		-DLLVM_EXTERNAL_LIT=/usr/bin/lit \
		$CMAKE_CROSSOPTS .
	ninja -C build
}

check() {
	ninja -C build check-llvm-spirv
}

package() {
	DESTDIR="$pkgdir" ninja -C build install
}

sha512sums="
c23ef81802d2bf743564762815d7375a804bdf8029efd7430faea0b48b5e30a9778c1175f52309b522a07aadf8ff77461b912c1fb3b95af9b09273a483eac82a  SPIRV-LLVM-Translator-12.0.0.tar.gz
"
